//
//  WWAboutUsViewController.m
//  WorthWhile
//
//  Created by Mac on 2018/5/11.
//  Copyright © 2018年 stoneobs.icloud.com. All rights reserved.
//

#import "THAboutUsViewController.h"
@interface THAboutUsViewController ()
@property(nonatomic, strong) STMonitorHomeViewController                     *vc;/**<  */
@property(nonatomic, strong) NSMutableArray<NSArray*>                     *dataSouce;/**<  */
@property(nonatomic, strong) NSString                     *about_us;/**<  */
@end

@implementation THAboutUsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.backgroundColor = UIColor.whiteColor;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    self.tableView.width = UISCREEN_WIDTH - 80;
    self.tableView.centerX = UISCREEN_WIDTH / 2;
    self.title = @"关于我们";
    [self configSubView];
    [self config_dataSouce];
//    [BFBaseConfigDataController stoneobs_fun_get_keyword:@"about_us" handle:^(NSString * _Nonnull h5String) {
//        self.about_us = h5String;
//        [self configSubView];
//        [self config_dataSouce];
//    }];
    
    
    
    
    

    // Do any additional setup after loading the view.
}

#pragma mark --subView
- (void)configSubView{
    UIView * header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.width, 200)];
    STButton * logoButton = [[STButton alloc] initWithFrame:CGRectMake(0, 70, 90, 90)
                                                      title:nil
                                                 titleColor:nil
                                                  titleFont:0
                                               cornerRadius:8
                                            backgroundColor:STONEOBS_UI_THEME_BACKGROUNDCOLOR
                                            backgroundImage:[UIImage imageNamed:@"logo"]
                                                      image:nil];
    logoButton.centerX = self.tableView.width / 2;
    logoButton.userInteractionEnabled = NO;
    [header addSubview:logoButton];
    
    CGFloat top = logoButton.bottom + 10;
    ({
        STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(0, top, self.tableView.width, 30)
                                                         text:[NSString stringWithFormat:@"%@",UIApplication.stoneobs_fun_st_applictionDisplayName]
                                                    textColor:STONEOBS_UI_SECEND_TEXT_COLOR
                                                         font:16
                                                  isSizetoFit:NO
                                                textAlignment:NSTextAlignmentCenter];
        [header addSubview:titleLable];
        titleLable.font = [UIFont fontWithName:STONEOBS_UI_FONT_CU_NAME size:16];
        top = titleLable.bottom;
    });

    ({
        STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(0, top, self.tableView.width, 30)
                                                         text:[NSString stringWithFormat:@"v%@",UIApplication.stoneobs_fun_st_applictionVersin]
                                                    textColor:STONEOBS_UI_THIRD_TEXT_COLOR
                                                         font:16
                                                  isSizetoFit:NO
                                                textAlignment:NSTextAlignmentCenter];
        [header addSubview:titleLable];
        titleLable.font = [UIFont fontWithName:STONEOBS_UI_FONT_CU_NAME size:16];
        top = titleLable.bottom;
    });
    
    ({
        STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(0, top, self.tableView.width , 30)
                                                         text:@"sasdasdasdjaslkdasjdsakljdklasjdklasjdlajd"
                                                    textColor:STONEOBS_UI_THIRD_TEXT_COLOR
                                                         font:13
                                                  isSizetoFit:NO
                                                textAlignment:NSTextAlignmentCenter];
//        [header addSubview:titleLable];
        [titleLable stoneobs_fun_st_autoadjustTextHeight];
        top = titleLable.bottom;
        

    });
    
    header.height = top + 30;
    self.tableView.tableHeaderView = header;
    
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(configVersionView)];
    tap.numberOfTapsRequired =  5;
    [header addGestureRecognizer:tap];
    
}
#pragma mark --Action Method
- (void)configVersionView{
    UISwitch * switchView = [UISwitch new];
    BOOL isOpen = [NSUserDefaults.standardUserDefaults boolForKey:WH_HUANJ_USE];
    [switchView setOn:isOpen];
    [switchView addTarget:self action:@selector(willChangeAction:) forControlEvents:UIControlEventValueChanged];
    
    STMonitorHomeViewController * vc = [STMonitorHomeViewController new];
    UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:vc];
    [self presentViewController:nav animated:YES completion:nil];
    [vc stoneobs_fun_st_setLeftItemWithView:switchView];
    self.vc = vc;

   
}
- (void)willChangeAction:(UISwitch*)sender{
    [[NSUserDefaults standardUserDefaults] setBool:sender.on forKey:WH_HUANJ_USE];
    [self.vc stoneobs_fun_st_showAlertTitle:@"成功" message:@"请重新登录" andWithBlock:^(NSString *name) {
        [STTools_UserManger.defult stoneobs_fun_removeUserPreferce];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            exit(0);
        });
        
    }];
    [[NSUserDefaults standardUserDefaults] synchronize];
}
- (void)config_dataSouce{
    self.dataSouce = NSMutableArray.new;

    
    ({
       NSArray * array = @[
           [[STTools_TableEasyModel alloc] initWithTextString:@"企业资质" detailString:@""],
           [[STTools_TableEasyModel alloc] initWithTextString:@"用户服务协议" detailString:@""],
           [[STTools_TableEasyModel alloc] initWithTextString:@"隐私政策" detailString:@""]
       ];
        [self.dataSouce addObject:array];
    });
    
    [self.tableView reloadData];
}
#pragma --mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return self.dataSouce.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.dataSouce[section].count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 50;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 0.01;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 20;
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * reuseIdentifier =  @"cell";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuseIdentifier];
        
    }
    STTools_TableEasyModel * model = self.dataSouce[indexPath.section][indexPath.row];
    [cell setSt_tableEasyModel:model];
    if (model.detailString.length > 0) {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }else{
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    
    return cell;
}
#pragma --mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    STTools_TableEasyModel * model = self.dataSouce[indexPath.section][indexPath.row];
    if ([model.textString isEqualToString:@"企业资质"]) {
        [BFBaseConfigDataController stoneobs_fun_get_keyword:@"qiyezizhi" handle:^(NSString * _Nonnull h5String) {
            STTools_WebViewController * webVc = [[STTools_WebViewController alloc] initWithH5String:h5String];
            webVc.forceTitle = model.textString;
            [self pushViewController:webVc animated:1];
        }];
    }
    if ([model.textString isEqualToString:@"用户服务协议"]) {
        [BFBaseConfigDataController stoneobs_fun_get_keyword:@"yonghuxieyi" handle:^(NSString * _Nonnull h5String) {
            STTools_WebViewController * webVc = [[STTools_WebViewController alloc] initWithH5String:h5String];
            webVc.forceTitle = model.textString;
            [self pushViewController:webVc animated:1];
        }];
    }
    if ([model.textString isEqualToString:@"隐私政策"]) {
        [BFBaseConfigDataController stoneobs_fun_get_keyword:@"yinsizhengce" handle:^(NSString * _Nonnull h5String) {
            STTools_WebViewController * webVc = [[STTools_WebViewController alloc] initWithH5String:h5String];
            webVc.forceTitle = model.textString;
            [self pushViewController:webVc animated:1];
        }];
    }


    
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
}
@end

